const equipmentLedgerMixin = {
  data() {
    return {
      option: {
        height: 'calc(100vh - 410px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        // searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        selection: true,
        menuWidth: 200, //弹框内字段宽度属性
        dialogWidth: 880, //弹框宽度属性
        labelWidth: '110',
        dialogClickModal: false,
        columnBtn: false,
        searchMenuPosition: 'right',
        column: [
          {
            label: '设备编码',
            prop: 'code',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入设备编码'
              }
            ]
          },
          {
            label: '设备名称',
            prop: 'name',
            search: true
          },
          {
            label: '设备类型',
            prop: 'type',
            search: true,
            type: 'select',
            dicData: [
              { label: '机台', value: 'MACHINE' },
              { label: '打印机', value: 'PRINTER' }
            ]
          },
          {
            label: '设备品牌',
            prop: 'brand'
          },
          {
            label: '设备型号',
            prop: 'model'
          },
          {
            label: '设备规格',
            prop: 'specification'
          },
          {
            label: '所在产线',
            prop: 'lineName'
          },
          {
            label: '状态',
            prop: 'status',
            search: true,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=equipment_ledger_status',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          }
        ]
      },
      dialogOption: {
        emptyBtn: false,
        submitBtn: false,
        detail: false,
        labelWidth: 160,
        group: [
          {
            label: '基本信息',
            arrow: false,
            prop: 'baseInfo',
            labelWidth: 100,
            display: true,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '设备编码',
                prop: 'code',
                span: 8,
                rules: [
                  {
                    required: true,
                    message: '请输入设备编码'
                  }
                ]
              },
              {
                label: '设备名称',
                prop: 'name',
                span: 8,
                rules: [
                  {
                    required: true,
                    message: '请输入设备名称'
                  }
                ]
              },
              {
                label: '设备类型',
                prop: 'type',
                span: 8,
                type: 'select',
                dicData: [
                  { label: '机台', value: 'MACHINE' },
                  { label: '打印机', value: 'PRINTER' }
                ],
                rules: [
                  {
                    required: true,
                    message: '请选择设备类型'
                  }
                ]
              },
              {
                label: '设备品牌',
                prop: 'brand',
                span: 8,
                rules: [
                  {
                    required: true,
                    message: '请输入品牌'
                  }
                ]
              },
              {
                label: '设备型号',
                prop: 'model',
                span: 8
              },
              {
                label: '设备规格',
                prop: 'specification',
                span: 8
              },
              {
                label: '备注',
                prop: 'remark',
                type: 'textarea',
                minRows: 3,
                maxRows: 3,
                span: 8
              }
            ]
          },
          {
            label: '车间信息',
            arrow: false,
            prop: 'workshopInfo',
            labelWidth: 100,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '所在车间',
                prop: 'workshopName',
                type: 'search',
                disabled: true,
                span: 8,
                appendClick: () => {
                  this.openWorkshopCommonModal();
                },
                rules: [
                  {
                    required: true,
                    message: '请输入所在车间'
                  }
                ]
              },
              {
                label: '所在产线',
                prop: 'lineName',
                type: 'search',
                disabled: true,
                span: 8,
                appendClick: () => {
                  this.openLineCommonModal();
                },
                rules: [
                  {
                    required: true,
                    message: '请输入所在产线'
                  }
                ]
              },
              {
                label: '负责人员',
                prop: 'principalName',
                type: 'search',
                disabled: true,
                span: 8,
                appendClick: () => {
                  this.openUserCommonModal();
                }
              }
            ]
          },
          {
            label: '网络接口信息',
            arrow: false,
            prop: 'networkInterfaceInfo',
            labelWidth: 100,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: 'IP地址',
                prop: 'ip',
                span: 8,
                rules: [
                  {
                    required: false,
                    trigger: 'blur',
                    validator: (rule, value, callback) => {
                      if (value) {
                        let result = this.getValidResult('ip', value);
                        if (result) {
                          callback();
                        } else {
                          callback(new Error('请输入正确的IP地址'));
                        }
                      } else {
                        callback();
                      }
                    }
                  }
                ]
              },
              {
                label: '端口',
                prop: 'port',
                span: 8,
                rules: [
                  {
                    required: false,
                    trigger: 'blur',
                    validator: (rule, value, callback) => {
                      if (value) {
                        let result = this.getValidResult('port', value);
                        if (result) {
                          callback();
                        } else {
                          callback(new Error('请输入正确的端口号'));
                        }
                      } else {
                        callback();
                      }
                    }
                  }
                ]
              },
              {
                label: '主机名称',
                prop: 'hostName',
                span: 8
              },
              {
                label: '网络协议类型',
                prop: 'protocol',
                type: 'select',
                dicUrl: '/api/blade-system/dict/dictionary?code=protocol',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                span: 8
              }
            ]
          },
          {
            label: '附件信息',
            arrow: false,
            prop: 'attachInfo',
            labelWidth: 110,
            display: true,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '设备图片',
                prop: 'EQUIPMENT_PICTURE',
                type: 'upload',
                span: 8
              },
              {
                label: '验收报告附件',
                prop: 'ACCEPTANCE_REPORT',
                type: 'upload',
                span: 8
              },
              {
                label: '投产验证附件',
                prop: 'PRODUCTION_VALIDATION',
                type: 'upload',
                span: 8
              }
            ]
          }
        ]
      }
    };
  },
  methods: {
    /**
     * 打开产线选择模态框
     */
    openLineCommonModal() {
      this.modalName = 'lineModal';
      this.$refs.commonModalTemplate.showModal();
      let url = '';
      if (this.form.workshopId) {
        url = `/api/mes-product/product/line/page?workshopId=${this.form.workshopId}`;
      } else {
        url = '/api/mes-product/product/line/page';
      }
      this.tableOption = {
        modalTitle: '选择产线信息（双击进行选择）',
        url: url,
        isPage: true,
        rowSelectionType: 'single',
        menu: false,
        editBtn: false,
        menuWidth: 100,
        columnDefs: [
          {
            label: '产线名称',
            prop: 'name',
            search: true
          },
          {
            label: '产线编码',
            prop: 'code',
            search: true
          }
        ]
      };
    },
    openWorkshopCommonModal() {
      this.modalName = 'workshopModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择车间信息（双击进行选择）',
        url: '/api/mes-product/workshop/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '车间编码',
            prop: 'code',
            search: true
          },
          {
            label: '车间名称',
            prop: 'name',
            search: true
          }
        ]
      };
    },
    /**
     * 打开用户选择模态框
     */
    openUserCommonModal() {
      this.modalName = 'principalModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择负责人员（双击进行选择）',
        url: '/api/blade-system/user/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '用户姓名',
            prop: 'realName',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '所属部门',
            prop: 'deptName',
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '职务',
            prop: 'postName'
          },
          {
            label: '用户平台',
            prop: 'userTypeName'
          }
        ]
      };
    }
  }
};

export default equipmentLedgerMixin;
